#include "CommonResource.h"
#include <cassert>
#include <iostream>
using namespace std;

CommonResource* CommonResource::mInstance = 0;

CommonResource::CommonResource() {
/* Init. some default values. */
    //CommonResource::mInstance->setQuit(false);
    //CommonResource::mInstance->setScreenManager(new ScreenManager); /* Here ScreenManager is initialized */
    //CommonResource::mInstance->setActiveScreen(1);

    mQuit = false;
    mScreenManager = new ScreenManager();
    mActiveScreen = 1;
}

CommonResource* CommonResource::getInstance() {
    if(mInstance == NULL) {
        mInstance = new CommonResource();           
    }
    return mInstance;
}

void CommonResource::setScreenManager(ScreenManager* sm) {
    assert(sm != NULL);
    mScreenManager = sm;
}

ScreenManager* CommonResource::getScreenManager() const {
    assert(mScreenManager != NULL);
    return mScreenManager;       
}

void CommonResource::setActiveScreen(int pScreen) {
    assert(pScreen > 0);
    assert(pScreen < 3); /* assumes just two screens are used */
    mActiveScreen = pScreen;
}

int CommonResource::getActiveScreen()  {    
    assert(mActiveScreen > 0);
    //assert(mActiveScreen < 3); /* assumes just two screens are used */
    return mActiveScreen;
}

KeyboardHandler * CommonResource::getKeyboardHandler() {
    if (mKeyboardHandler == NULL){
        mKeyboardHandler = new KeyboardHandler();
    }
    return mKeyboardHandler;
}

void CommonResource::setKeyboardHandler(KeyboardHandler *kb) {
    assert(kb != NULL);
    mKeyboardHandler = kb; 
}

void CommonResource::setQuit(bool quit) {
    mQuit = quit;
}

bool CommonResource::getQuit()  {
    return mQuit;
}

